

$(function(){
    $.getJSON('/tts/batch/data',function(data){
        app.batchs = data
    });
});

var app = new Vue({
  el:'#app',
  data: {
      batchs: [],
      lists: [],
      batchFormVisible: false,
      batchForm: {
          id:null,
          batchyear:''
      },
      listFormVisible: false,
      listForm: {
          id:null,
          code:'',
          name:'',
          unit:'',
          tutorType:'',
          direction:'',
          isParttime:''
      },
      formLabelWidth: '120px'
  },
  methods: {
      show:function(id){
          console.log("show"+id);

          $.get("/tts/batch/lists/"+id)
              .done(function(data){
                  app.lists = data ;
              }).fail(function(data){
                  $this.$message({
                      message:'信息验证失败，请填写正确的信息',
                      type:'error',
                      showClose:true,
                      duration:3000
                  });
          });
      },
      openformatter:function (row,column) {
          if(row.isOpen) return "开放"
          return "不开放"
      },
      parttimeformatter:function (row,column) {
          if(row.isParttime) return "兼职"
          return "全职"
      },
      addBatch:function (year) {
          console.log("addbatch"+year);
          var data = [];
          var $this = this;
          data.push({name:'year',value:year});

          $.post("/tts/batch/add",data)
              .done(function(data){
                  $this.$message({
                      message:'添加成功',
                      type:'success'
                  });
                  window.location.reload();
              }).fail(function(data){
              $this.$message({
                  message:'信息验证失败，请填写正确的信息',
                  type:'error',
                  showClose:true,
                  duration:3000
              });
          });

          $this.batchFormVisible = false;
      },
      getTemplate:function () {
          console.log("getTemplate");
          window.open("/public/template/batchTemplate.xls");
      },
      toggle:function (row) {
          console.log(row);
          id = row.id;
          var $this = this;
          var data = [];
          data.push({name:'id',value:id});

          $.post("/tts/batch/toggle",data)
              .done(function(data){
                  row.isOpen = !row.isOpen;
              }).fail(function(data){
                  $this.$message({
                      message:'信息验证失败，请填写正确的信息',
                      type:'error',
                      showClose:true,
                      duration:3000
                  });
          });
      },
      handleEditList:function(row){
          this.listFormVisible=true;
          this.listForm = row;
      },
      handleEditTutor:function (code) {
          window.open("/tts/tutor/adminIndex/"+code);
      },
      editList:function () {
          var _this = this;
          $.post("/tts/batch/editlist",getJSONArrayFromObject(_this.listForm,"list"))
              .done(function(data){
                  _this.$message({
                      message:'保存成功',
                      type:'success'
                  });
                  window.location.reload();
              }).fail(function(data){
              _this.$message({
                  message:'信息验证失败，请填写正确的信息',
                  type:'error',
                  showClose:true,
                  duration:3000
              });
          });
          _this.listFormVisible = false;
      },
      tutorStat:function(){
          window.open("http://newstu.sufe.edu.cn/sys/tableau?sheet=tutorshow_report/sheet0?:iid=1");
      }

  }
})
